package com.fjc.Filter;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by fjc on 2019/2/17.
 */
public class TokenInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入拦截器");
        //验证session是否存在
        String token = request.getHeader("token");
        if (!StringUtils.isBlank(token)) {
            return true;
        }
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().print(JSONObject.parse("{\"code\":0,\"msg\":\"您未登陆\"}"));
        return false;
    }
}
